﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using University.Workshop.DataAccess;
using University.Workshop.Model;

namespace University.Workshop.ClientApp
{
    /// <summary>
    /// Interaction logic for Loan.xaml
    /// </summary>
    public partial class Loan : Window
    {
        User user;
        public Loan()
        {
            InitializeComponent();
        }
        public Loan(User userReceived)
        {
            InitializeComponent();
            user = userReceived;
            labelUserName.Content = user.Name;
            labelUserChips.Content = user.Chips;
            if (user.Loan != "no")
            {
                button500.IsEnabled = false;
                button1000.IsEnabled = false;
                button2500.IsEnabled = false;
                button5000.IsEnabled = false;
                button10000.IsEnabled = false;
                buttonPay.IsEnabled = true;
                labelPay.Content = "pay "+ user.Loan + " chips";
                labelPay.Visibility = Visibility.Visible; 
            }
            else
            {
                button500.IsEnabled = true;
                button1000.IsEnabled = true;
                button2500.IsEnabled = true;
                button5000.IsEnabled = true;
                button10000.IsEnabled = true;
                buttonPay.IsEnabled = false;
                labelPay.Visibility = Visibility.Hidden;
            }
        }
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            
                Client client = new Client();
                client.Send("92 " + user.Name + " " + 500);
                string resultfour = client.Receive();
                user.Chips = user.Chips + 500;
                MessageBox.Show("Now you have 500 additional chips");
                this.Close();
        }

        private void button1000_Click(object sender, RoutedEventArgs e)
        {
            Client client = new Client();
            client.Send("92 " + user.Name + " " + 1000);
            string resultfour = client.Receive();
            user.Chips = user.Chips + 1000;
            MessageBox.Show("Now you have 1000 additional chips");
            this.Close();
        }

        private void button2500_Click(object sender, RoutedEventArgs e)
        {
            Client client = new Client();
            client.Send("92 " + user.Name + " " + 2500);
            string resultfour = client.Receive();
            user.Chips = user.Chips + 2500;
            MessageBox.Show("Now you have 2500 additional chips");
            this.Close();
        }

        private void button5000_Click(object sender, RoutedEventArgs e)
        {
            Client client = new Client();
            client.Send("92 " + user.Name + " " + 5000);
            string resultfour = client.Receive();
            user.Chips = user.Chips + 5000;
            MessageBox.Show("Now you have 5000 additional chips");
            this.Close();
        }

        private void button10000_Click(object sender, RoutedEventArgs e)
        {
            Client client = new Client();
            client.Send("92 " + user.Name + " " + 10000);
            string resultfour = client.Receive();
            user.Chips = user.Chips + 10000;
            MessageBox.Show("Now you have 10000 additional chips");
            this.Close();
        }

        private void buttonPay_Click(object sender, RoutedEventArgs e)
        {
            Client client = new Client();
            client.Send("93 " + user.Name);
            string resultfour = client.Receive();
            user.Chips = user.Chips - Convert.ToInt16(user.Loan);
            MessageBox.Show("thanks for paying the loan");
            this.Close();
        }
    }
}
